package com.yyfax.pay.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.yyfax.framework.yyfax.BaseEnum;

/**
 * 支付类型枚举
 * 
 * @author buyi
 * @date 2017-04-12 20:06:18
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public final class PayTypeEnum extends BaseEnum<String> {

	/** 枚举集合 */
	protected static final Map<String, PayTypeEnum> values = new HashMap<>();

	public static final String ENUM_KEY = "PAY_TYPE";

	public static final PayTypeEnum COMMON = PayTypeEnum.build("COMMON", "0", "通用");

	public static final PayTypeEnum PAY = PayTypeEnum.build("PAY", "1", "支付");

	public static final PayTypeEnum PAY_OUT = PayTypeEnum.build("PAY_OUT", "2", "代付");

	public static final PayTypeEnum CARD_BIN = PayTypeEnum.build("CARD_BIN", "3", "卡bin");

	public static final PayTypeEnum AUTH = PayTypeEnum.build("AUTH", "4", "独立鉴权");

	public static final PayTypeEnum PAY_IN = PayTypeEnum.build("PAY_IN", "5", "代扣");

	public static final PayTypeEnum BATCH_PAY_IN = PayTypeEnum.build("BATCH_PAY_IN", "6", "批量代扣");

	public static final PayTypeEnum BATCH_PAY_OUT = PayTypeEnum.build("BATCH_PAY_OUT", "7", "批量代付");

	public static final PayTypeEnum FILE_TRADE = PayTypeEnum.build("FILE_TRADE", "8", "交易");

	public static final PayTypeEnum FILE_CHECK = PayTypeEnum.build("FILE_CHECK", "9", "报备");
	
	public static final PayTypeEnum FILE_ACCOUNT = PayTypeEnum.build("FILE_ACCOUNT", "10", "对账");

	/**
	 * 构造函数
	 */
	private PayTypeEnum(String name, String value, String remark) {
		super(name, value, remark);
	}

	public static List<PayTypeEnum> values() {
		return new ArrayList<PayTypeEnum>(values.values());
	}

	/**
	 * 不存在则添加,存在则更新(用于数据库加载时)
	 * 
	 * @author jiangmy
	 * @date 2016-12-05 19:31:30
	 * @param name
	 * @param value
	 * @param remark
	 * @return
	 */
	public static final PayTypeEnum build(String name, String value, String remark) {
		PayTypeEnum e = values.get(name);
		if (e == null) {
			e = new PayTypeEnum(name, value, remark);
			values.put(name, e);
		} else {
			e.value = value;
			e.remark = remark;
		}
		return e;
	}

	public static final PayTypeEnum fromValue(String value) {
		for (PayTypeEnum e : values.values()) {
			if (StringUtils.equals(value, e.getValue())) {
				return e;
			}
		}
		return null;

	}
}
